# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Thomas Bächler <thomas@archlinux.org>

pkgname=bftpd
pkgver=4.9
pkgrel=1
pkgdesc='Small, easy-to-configure FTP server'
url='http://bftpd.sourceforge.net/'
arch=('x86_64')
license=('GPL')
depends=('pam' 'zlib' 'glibc')
backup=(etc/bftpd.conf
        etc/logrotate.d/bftpd
        etc/pam.d/bftpd
        etc/xinetd.d/bftpd)
source=(https://downloads.sourceforge.net/sourceforge/bftpd/bftpd-${pkgver}.tar.gz
        bftpd.logrotate
        bftpd.pam
        bftpd.xinetd
        bftpd.service
        bftpd.socket
        bftpd_AT.service
        bftpd.tmpfiles
        bftpd-4.9-Makefile.patch)
sha256sums=('cdd8cdfbca44309bac47b2d6cc1efd7c63ff3535a1803ace89f73dc9128df28e'
            '4768016884e2aaaaecc1412353f7dfaf19d2dab0e03789c4df9bbae2d56dfb7a'
            '57dfd072fd7ef0018c6b0a798367aac1abb5979060ff3f9df22d1048bb71c0d5'
            '18096a2f6914fecd9f36721247d170ba48b986225dae3564cb2d3b0e6f18c35a'
            '6047c33d1694445aa1b0cfad4ba796ff6c1635eb86c8398f39c0f9180d9490be'
            '0f930f803cf40dda1336ddb89e925b8f7b703518484b8a1a41153f0828de404c'
            '97dba309c60029c498f353b39778c6594deef8a3b98ca09889857ca920674ccc'
            '0be0b772ca19362173152fa7a8d7578faa535995b1e150bafec7a28e649b399f'
            '93248ffd3f99336e704aeedaaac207cb2e25f64998fd5c274fd29cb548f14acc')
prepare() {
  cd ${pkgname}
  patch -Np1 < ../bftpd-4.9-Makefile.patch
  # Fix default in config file
  sed 's|#ROOTDIR="/path/for/anonymous/user"|# bftpd interprets ROOTDIR="%h" (the default), as ROOTDIR="/" for the anonymous user, override it\n  ROOTDIR="/srv/ftp"|' -i bftpd.conf
  rm -f config.{cache,status}
  autoreconf -fiv
}

build() {
  cd ${pkgname}
    ./configure \
    --prefix=/usr \
    --enable-pam \
    --enable-libz \
    --mandir=/usr/share/man \
    --sysconfdir=/etc \
    --sbindir=/usr/bin
  make
}

package() {
  cd ${pkgname}
  make DESTDIR="${pkgdir}" install
  rm -rf "${pkgdir}/usr/var"
  install -Dm 644 ../bftpd.service "${pkgdir}/usr/lib/systemd/system/bftpd.service"
  install -Dm 644 ../bftpd_AT.service "${pkgdir}/usr/lib/systemd/system/bftpd@.service"
  install -Dm 644 ../bftpd.socket "${pkgdir}/usr/lib/systemd/system/bftpd.socket"
  install -Dm 644 ../bftpd.tmpfiles "${pkgdir}/usr/lib/tmpfiles.d/bftpd.conf"
  install -Dm 644 ../bftpd.logrotate "${pkgdir}/etc/logrotate.d/bftpd"
  install -Dm 644 ../bftpd.pam "${pkgdir}/etc/pam.d/bftpd"
  install -Dm 644 ../bftpd.xinetd "${pkgdir}/etc/xinetd.d/bftpd"
}

# vim: ts=2 sw=2 et:
